<template>
  <el-menu
    :default-active="activeIndex"
    class="el-menu-vertical-demo"
    @select="handleMenuSelect"
  >
    <el-menu-item index="company-posmanage">
      <i class="el-icon-user-solid"></i>
      职位管理</el-menu-item
    >
    <el-menu-item index="company-message">
      <i class="el-icon-phone-outline"></i>
      公司信息</el-menu-item
    >
    <el-menu-item index="company-seeker">
      <i class="el-icon-user"></i>
      推荐牛人</el-menu-item
    >
    <el-menu-item index="ComChat">
      <i class="el-icon-user"></i>
      在线聊天</el-menu-item
    >
  </el-menu>
</template>
    
    <script>
export default {
  data() {
    return {
      activeIndex: "", // 默认选中的菜单项
    };
  },
  created() {
    // 在组件创建时获取当前路由的名称，并设置为 activeIndex 的初始值
    this.activeIndex = this.$route.name || "company-posmanage"; // 如果没有路由名称，默认为 "manage"
  },
  methods: {
    handleMenuSelect(index) {
      // 如果当前选中的菜单项已经是目标路由，则不执行重复导航
      if (this.activeIndex === index) {
        return;
      }
      switch (index) {
        case "company-posmanage":
          this.$router.push({ name: "company-posmanage" });
          break;
        case "company-message":
          this.$router.push({ name: "company-message" });
          break;
        case "company-seeker":
          this.$router.push({ name: "company-seeker" });
          break;
        case "ComChat":
          this.$router.push({ name: "ComChat" });
          break;
        default:
          break;
      }
    },
  },
};
</script>
    
    <style>
.el-menu-vertical-demo {
  background-color: rgb(211, 220, 230);
}
/* 可以根据需要自定义样式 */
</style>